home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / prefix.c < prev    next >
C/C++ Source or Header  |  1993-11-28  |  53KB  |  1,322 lines

  1. /***********************************************************************/
  2. /* PREFIX.C - Prefix commands.                                         */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991-1993 Mark Hessling
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  *
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  *
  25.  *
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 5314
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38.  
  39. /*
  40. $Header: C:\THE\RCS\prefix.c 1.4 1993/09/01 16:26:56 MH Interim MH $
  41. */
  42.  
  43. #include <stdio.h>
  44.  
  45. #include "the.h"
  46. #include "proto.h"
  47. /*-------------------------- declarations -----------------------------*/
  48. #ifdef PROTO
  49. static int parse_prefix_command(int,char *,char *);
  50. static int invalidate_prefix(int);
  51. static int prefix_makecurr(int,int,long);
  52. static int prefix_add(int,int,long);
  53. static int prefix_duplicate(int,int,long);
  54. static int prefix_copy(int,int,long);
  55. static int prefix_move(int,int,long);
  56. static int prefix_delete(int,int,long);
  57. static int prefix_shift_left(int,int,long);
  58. static int prefix_shift_right(int,int,long);
  59. static int prefix_block_duplicate(int,int,long);
  60. static int prefix_block_copy(int,int,long);
  61. static int prefix_block_move(int,int,long);
  62. static int prefix_block_delete(int,int,long);
  63. static int prefix_block_shift_left(int,int,long);
  64. static int prefix_block_shift_right(int,int,long);
  65. void clear_pending_prefix_command(int ,LINE *);
  66. static int find_bottom_ppc(int,int);
  67. static int find_target_ppc(int *);
  68. static long calculate_target_line(void);
  69. #if !defined(NOREXX)
  70. static int try_rexx_prefix_macro(int);
  71. #endif
  72. static char *substr(char *, char *, int, int);
  73. #else
  74. static int parse_prefix_command();
  75. static int invalidate_prefix();
  76. static int prefix_makecurr();
  77. static int prefix_add();
  78. static int prefix_duplicate();
  79. static int prefix_copy();
  80. static int prefix_move();
  81. static int prefix_delete();
  82. static int prefix_shift_left();
  83. static int prefix_shift_right();
  84. static int prefix_block_duplicate();
  85. static int prefix_block_copy();
  86. static int prefix_block_move();
  87. static int prefix_block_delete();
  88. static int prefix_block_shift_left();
  89. static int prefix_block_shift_right();
  90. void clear_pending_prefix_command();
  91. static int find_bottom_ppc();
  92. static int find_target_ppc();
  93. static long calculate_target_line();
  94. static char *substr();
  95. #endif
  96. /*---------------------------------------------------------------------*/
  97. /* The following two are to specify the first and last items in the    */
  98. /* linked list for prefix synonyms.                                    */
  99. /*---------------------------------------------------------------------*/
  100. LINE *first_prefix_synonym=NULL;
  101. LINE *last_prefix_synonym=NULL;
  102. /*---------------------------------------------------------------------*/
  103.  
  104. #define PPC_NO_TARGET        (-1)
  105. #define PPC_NO_COMMAND       (-2)
  106. #define PPC_TARGET_PREVIOUS  0
  107. #define PPC_TARGET_FOLLOWING 1
  108. /* the above two defines correspond to the position in the pc[] array  */
  109. /* and should be changed if the position in pc[] array changes.        */
  110.  
  111. #define NUMBER_PREFIX_COMMANDS 17
  112.  static PREFIX_COMMAND pc[NUMBER_PREFIX_COMMANDS] =
  113.   {
  114.    {(char *)"p",1,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,NULL},
  115.    {(char *)"f",1,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,NULL},
  116.    {(char *)"\"\"",2,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_block_duplicate},
  117.    {(char *)"cc",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,prefix_block_copy},
  118.    {(char *)"mm",2,TRUE,TRUE,FALSE,TRUE,TRUE,FALSE,FALSE,prefix_block_move},
  119.    {(char *)"dd",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_delete},
  120.    {(char *)"<<",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_shift_left},
  121.    {(char *)">>",2,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,prefix_block_shift_right},
  122.    {(char *)"\"",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_duplicate},
  123.    {(char *)"c",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,prefix_copy},
  124.    {(char *)"m",1,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE,FALSE,prefix_move},
  125.    {(char *)"d",1,TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,prefix_delete},
  126.    {(char *)"<",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_left},
  127.    {(char *)">",1,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,prefix_shift_right},
  128.    {(char *)"i",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,prefix_add},
  129.    {(char *)"a",1,TRUE,TRUE,FALSE,FALSE,FALSE,TRUE,FALSE,prefix_add},
  130.    {(char *)"/",1,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,prefix_makecurr},
  131.   };
  132.  
  133. char pending_prefix_command[PREFIX_WIDTH+1]="";
  134. long prefix_current_line;
  135. bool in_prefix_macro=FALSE;     /* indicate if processing prefix macro */
  136. /*-------------------------- external data ----------------------------*/
  137. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  138. /***********************************************************************/
  139. #ifdef PROTO
  140. int execute_prefix_commands(void)
  141. #else
  142. int execute_prefix_commands()
  143. #endif
  144. /***********************************************************************/
  145. {
  146. /*-------------------------- external data ----------------------------*/
  147.  extern char number_of_files;
  148. /*--------------------------- local data ------------------------------*/
  149.  register int i;
  150.  int len,cmd_idx,rc,ppc_idx;
  151.  char cmd[PREFIX_WIDTH+1];
  152.  char mult[PREFIX_WIDTH+1];
  153.  int first_pending = (-1);
  154.  long long_mult=0L;
  155.  long start_line,number_lines,target_line;
  156.  int top_ppc,bot_ppc,target_ppc;
  157.  int number_prefix_commands;
  158. /*--------------------------- processing ------------------------------*/
  159. #ifdef TRACE
  160.  trace_function("prefix.c:  execute_prefix_commands");
  161. #endif
  162.  post_process_line(CURRENT_VIEW->focus_line);
  163. /*---------------------------------------------------------------------*/
  164. /* This variable is set here because post_process_line() actually sets */
  165. /* CURRENT_VIEW->prefix_command_index.                                 */
  166. /*---------------------------------------------------------------------*/
  167.  number_prefix_commands = CURRENT_VIEW->prefix_command_index;
  168. /*---------------------------------------------------------------------*/
  169. /* For each pending prefix command for the current view, validate the  */
  170. /* command and parameters.                                             */
  171. /*---------------------------------------------------------------------*/
  172.  for (i=0;i<number_prefix_commands;i++)
  173.    {
  174. /*---------------------------------------------------------------------*/
  175. /* If a set point command, validate the name.                          */
  176. /*---------------------------------------------------------------------*/
  177.     if (CURRENT_VIEW->ppc[i].ppc_command[0] == '.')
  178.       {
  179.        if (isalpha(CURRENT_VIEW->ppc[i].ppc_command[1]))
  180.          {
  181.           if (execute_set_point(CURRENT_VIEW->ppc[i].ppc_command,CURRENT_VIEW->ppc[i].ppc_line_number,TRUE) != RC_OK)
  182.             {
  183.              invalidate_prefix(i);
  184.              continue;
  185.             }
  186.           clear_pending_prefix_command(i,(LINE *)NULL);
  187.           continue;
  188.          }
  189.        else
  190.          {
  191.           invalidate_prefix(i);
  192.           continue;
  193.          }
  194.       }
  195. /*---------------------------------------------------------------------*/
  196. /* If an invalid